/*
 * @Author       : LuHeQiu
 * @Date         : 2023-04-22 01:51:56
 * @LastEditTime : 2023-04-29 14:52:30
 * @LastEditors  : LuHeQiu
 * @Description  :
 * @FilePath     : /UnionLink-Ctrl/Hardware/rf.h
 * @HomePage     : https://www.luheqiu.com
 */
#ifndef __RF_H
#define __RF_H

#include "main.h"

/* ----------------------------- RF工作器定义 ----------------------------- */
#define RF_RADIO_CHANNEL \
    { 0xA5, 0xA4, 0xA3, 0xA2}

#define RF_ADDR_WIDTH  4

#define DYNAMIC_PACKET 1  // 1:动态数据包, 0:固定
#define REPEAT_CNT 5      // 重复次数

typedef enum RF_ModeType { 
    RF_MODE_TX = 0, 
    RF_MODE_RX 
} RF_ModeType;

typedef enum RF_SpeedType { 
    RF_SPEED_250K = 0, 
    RF_SPEED_1M, 
    RF_SPEED_2M 
} RF_SpeedType;

typedef enum RF_PowerType { 
    RF_POWER_N12_DBM = 0, 
    RF_POWER_N6_DBM, 
    RF_POWER_N4_DBM, 
    RF_POWER_0_DBM, 
    RF_POWER_1_DBM,
    RF_POWER_3_DBM,
    RF_POWER_5_DBM,
    RF_POWER_7_DBM,
} RF_PowerType;

uint8_t RF_Check(void);
void RF_Init(uint8_t* local_addr);
uint8_t RF_TxPacket(uint8_t* txbuf, uint8_t Length);
uint8_t RF_RxPacket(uint8_t* rxbuf, uint8_t* channel);
void RF_TxDataDirect(uint8_t* txbuf, uint8_t Length);
uint8_t RF_GetRSSI(void);
void RF_SetTxAddr(uint8_t* pAddr, uint8_t len);
void RF_SetRxAddr(uint8_t PipeNum, uint8_t* pAddr, uint8_t Len);
void RF_SetMode(RF_ModeType Mode);
void RF_SetHoppingPoint(uint8_t FreqPoint);
void RF_SetSpeed(RF_SpeedType Speed);
void RF_SetPower(RF_PowerType Power);


static void RF_Read_Buf(uint8_t RegAddr, uint8_t* pBuf, uint8_t len);
static uint8_t RF_Read_Reg(uint8_t RegAddr);
static void RF_Write_Reg(uint8_t RegAddr, uint8_t Value);
static void RF_Write_Buf(uint8_t RegAddr, uint8_t* pBuf, uint8_t len);
static uint8_t RF_Read_Status_Register(void);
static uint8_t RF_Clear_IRQ_Flag(uint8_t IRQ_Source);

#endif
